package com.fr.chart.plot;

import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.axis.ValueAxis;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.LineGlyph;
import com.fr.chart.core.glyph.PlotGlyph;
import com.fr.chart.core.glyph.RangeAxisGlyph;
import com.fr.chart.core.glyph.RangePlotGlyph;
import com.fr.data.ChartData;
import java.awt.Color;

public class RangePlot extends Plot
{
  private static final long serialVersionUID = -7011404700170399167L;
  private Color middleLine2DColor = Color.black;
  private int middlLineStyle = 1;
  private Color minToAverageColor = new Color(215, 214, 214);
  private Color averageToMaxColor = new Color(240, 239, 239);
  private ValueAxis valueAxis;
  private double seriesWidth = 4.0D;

  public RangePlot()
  {
    setValueAxis(new ValueAxis());
    getValueAxis().setPosition(3);
    ValueAxis localValueAxis = getValueAxis();
    localValueAxis.setMainGridColor(null);
    localValueAxis.setMainGridStyle(0);
    localValueAxis.setTickLength(20);
    localValueAxis.setSecTickLength(10);
    localValueAxis.setTickMarkType(3);
    localValueAxis.setSecTickMarkType(3);
    localValueAxis.setMainStroke(1.0F);
    localValueAxis.setSecStroke(1.0F);
  }

  public void setValueAxis(ValueAxis paramValueAxis)
  {
    this.valueAxis = paramValueAxis;
  }

  public ValueAxis getValueAxis()
  {
    return this.valueAxis;
  }

  public void setMiddlLineStyle(int paramInt)
  {
    this.middlLineStyle = paramInt;
  }

  public int getMiddlLineStyle()
  {
    return this.middlLineStyle;
  }

  public void setSeriesWidth(double paramDouble)
  {
    this.seriesWidth = paramDouble;
  }

  public double getSeriesWidth()
  {
    return this.seriesWidth;
  }

  public void setMiddleLine2DColor(Color paramColor)
  {
    this.middleLine2DColor = paramColor;
  }

  public Color getMiddleLine2DColor()
  {
    return this.middleLine2DColor;
  }

  public void setMinToAverageColor(Color paramColor)
  {
    this.minToAverageColor = paramColor;
  }

  public Color getMinToAverageColor()
  {
    return this.minToAverageColor;
  }

  public void setAverageToMaxColor(Color paramColor)
  {
    this.averageToMaxColor = paramColor;
  }

  public Color getAverageToMaxColor()
  {
    return this.averageToMaxColor;
  }

  public PlotGlyph createPlotGlyph(ChartData paramChartData)
  {
    RangePlotGlyph localRangePlotGlyph = new RangePlotGlyph();
    install4PlotGlyph(localRangePlotGlyph, paramChartData);
    createAxisGlyph(localRangePlotGlyph, paramChartData);
    createDataSeriesGlyph(localRangePlotGlyph);
    return localRangePlotGlyph;
  }

  public void install4PlotGlyph(RangePlotGlyph paramRangePlotGlyph, ChartData paramChartData)
  {
    super.install4PlotGlyph(paramRangePlotGlyph, paramChartData);
    paramRangePlotGlyph.setSeriesWidth(this.seriesWidth);
  }

  public void createAxisGlyph(RangePlotGlyph paramRangePlotGlyph, ChartData paramChartData)
  {
    RangePlotGlyph localRangePlotGlyph = paramRangePlotGlyph;
    RangeAxisGlyph localRangeAxisGlyph = new RangeAxisGlyph(this.valueAxis);
    localRangePlotGlyph.setRangeAxisGlyph(localRangeAxisGlyph);
    localRangeAxisGlyph.initMinMaxValue(getMinValueFromData(paramChartData), getMaxValueFromData(paramChartData));
    localRangeAxisGlyph.setLeftColor(this.minToAverageColor);
    localRangeAxisGlyph.setRightColor(this.averageToMaxColor);
  }

  private void createDataSeriesGlyph(RangePlotGlyph paramRangePlotGlyph)
  {
    LineGlyph localLineGlyph = new LineGlyph();
    localLineGlyph.setLineColor(this.middleLine2DColor);
    localLineGlyph.setLineStyle(this.middlLineStyle);
    paramRangePlotGlyph.setMiddleLineGlyph(localLineGlyph);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str2;
      String str1 = paramXMLableReader.getTagName();
      if ("ValueAxis".equals(str1))
        if (((str2 = paramXMLableReader.getAttr("class")) != null) && (str2.endsWith(".ValueAxis")))
          this.valueAxis = ((ValueAxis)paramXMLableReader.readXMLObject(new ValueAxis()));
      if ("MiddleLine".equals(str1))
      {
        if ((str2 = paramXMLableReader.getAttr("color")) != null)
          setMiddleLine2DColor(new Color(Integer.parseInt(str2), true));
        if ((str2 = paramXMLableReader.getAttr("style")) != null)
          setMiddlLineStyle(Integer.valueOf(str2).intValue());
      }
      if ("MinColor".equals(str1))
        if ((str2 = paramXMLableReader.getAttr("color")) != null)
          setMinToAverageColor(new Color(Integer.parseInt(str2), true));
      if ("MaxColor".equals(str1))
        if ((str2 = paramXMLableReader.getAttr("color")) != null)
          setAverageToMaxColor(new Color(Integer.parseInt(str2), true));
      if ("SeriesWidth".equals(str1))
        if ((str2 = paramXMLableReader.getAttr("value")) != null)
          setSeriesWidth(Double.valueOf(str2).doubleValue());
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("Plot");
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("MiddleLine").attr("color", getMiddleLine2DColor().getRGB()).attr("style", getMiddlLineStyle()).end();
    paramXMLPrintWriter.startTAG("MinColor").attr("color", getMinToAverageColor().getRGB()).end();
    paramXMLPrintWriter.startTAG("MaxColor").attr("color", getAverageToMaxColor().getRGB()).end();
    paramXMLPrintWriter.startTAG("SeriesWidth").attr("value", getSeriesWidth()).end();
    if (this.valueAxis != null)
      this.valueAxis.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    RangePlot localRangePlot = (RangePlot)super.clone();
    if (this.valueAxis != null)
      localRangePlot.valueAxis = ((ValueAxis)this.valueAxis.clone());
    return localRangePlot;
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof RangePlot))
      return false;
    RangePlot localRangePlot = (RangePlot)paramObject;
    if (!(super.equals(localRangePlot)))
      return false;
    if (!(Equals.equals(localRangePlot.getAverageToMaxColor(), getAverageToMaxColor())))
      return false;
    if (!(Equals.equals(localRangePlot.getMinToAverageColor(), getMinToAverageColor())))
      return false;
    if (!(Equals.equals(localRangePlot.getMiddleLine2DColor(), getMiddleLine2DColor())))
      return false;
    if (localRangePlot.getMiddlLineStyle() != getMiddlLineStyle())
      return false;
    if (localRangePlot.getSeriesWidth() != getSeriesWidth())
      return false;
    return (Equals.equals(localRangePlot.getValueAxis(), getValueAxis()));
  }
}